package com.bonjour.work.config;

import java.util.Map;

import javax.inject.Inject;
import javax.sql.DataSource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.bonjour.common.ibatis.IBatisConfigSupport;
import com.bonjour.common.view.IWebAuthenticationFilter;
import com.bonjour.common.view.WebConfigurationSupport;

/**
 * 服务配置
 **/
@Configuration
public class ApplicationConfiguration {

    @Configuration
    public static class WebConfiguration extends WebConfigurationSupport{
        @Override
        @Bean
        @Inject
        protected IWebAuthenticationFilter injectAuthenticationFilter(ApplicationContext context) {
            return new WebAuthenticationFilter(context);
        }
    }

    @Configuration
    public static class IBatisConfiguration extends IBatisConfigSupport {
        @Override
        protected void addMultiDataSource(Environment env, Map<String, DataSource> dsMap) {
            dsMap.put(IBatisDS.DEFAULT, super.hikariDataSource(env.getProperty("mysql.uri.default")));
        }
    }

//    /**
//     * 初始化JvmCluster默认配置
//     */
//    @Configuration
//    public static class JvmClusterConfiguration extends ClusterConfigSupport {
//        @Override
//        protected String clusterName(Environment env) {
//            return env.getProperty("jvm.srv.cluster.name");
//        }
//    }
}
